import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import 'package:test_app/app/index_controller.dart';

import 'package:test_app/core/base/base/base_view.dart';
import '../core/design_system/theme/color.dart';

class IndexView extends BaseView<IndexController> {
  const IndexView({super.key});

  @override
  bool get isHiddenNav => true;

  @override
  Widget body() {
    return PageView(
      physics: const BouncingScrollPhysics(),
      controller: controller.indexState.pageController,
      children: controller.pageList,
      onPageChanged: (int index) => controller.pageViewChange(index),
    );
  }

  @override
  Widget? bottom() {
    return Obx(
          () {
            final globalService = controller.globalService;
            return TDBottomTabBar(
                barHeight: 60,
                TDBottomTabBarBasicType.iconText,
                currentIndex: globalService.tabIndex.value,
                componentType: TDBottomTabBarComponentType.normal,
                navigationTabs: globalService.appBarList.map((item) => tabItem(item.title, item.icon, item.iconFill, item.index)).toList()
            );
          }
    );
  }

  /// 底部导航栏item
  TDBottomTabBarTabConfig tabItem(
      String title,
      IconData icon,
      IconData iconFill,
      int index,
      ) {
    return TDBottomTabBarTabConfig(
      tabText: title,
      selectedIcon: Icon(iconFill, color: primary),
      unselectedIcon: Icon(icon),
      onTap: () => controller.tabBarClick(index),
    );
  }
}